/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.worldjb.vk.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

/**
 * Настройки
 * @author alex_xpert
 */
public class MainProps {
    private static Properties props = new Properties();
    private static final String PROPS_FILENAME = "./mainprops.xml";
    
    private static void setDefault() {
        setProperty("access_token", "");
    }
    
    public static void load() {
        try {
            props.loadFromXML(new FileInputStream(PROPS_FILENAME));
        } catch(Exception ex) {
            System.out.println("ERROR! " + ex.getLocalizedMessage());
            setDefault();
        }
    }
    
    public static void save() {
        try {
            props.storeToXML(new FileOutputStream(PROPS_FILENAME), "Simple Java VK Client");
        } catch(Exception ex) {
            System.out.println("ERROR! " + ex.getLocalizedMessage());
        }
    }
    
    public static String getProperty(String key) {
        return props.getProperty(key);
    }
    
    public static void setProperty(String key, String value) {
        props.setProperty(key, value);
    }
    
}
